package com.bbcloud.controller.portal;

import com.bbcloud.common.ServerResponse;
import com.bbcloud.service.IHelpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by liuzhu on 2018/12/19.
 */
@Controller
@RequestMapping("/help/")
public class HelpController {

    @Autowired
    private IHelpService iHelpService;

    /**
     *提建议接口
     * @param token token
     * @param userId userId
     * @param file  file
     * @param description 建议
     * @param request   request
     * @return
     */
    @RequestMapping(value = "suggestion.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse suggestion(@RequestParam(value = "token", required = true) String token,
                                   @RequestParam(value = "userId", required = true) String userId,
                                   @RequestParam(value = "upload_file",required = false) MultipartFile file,
                                   @RequestParam(value = "description", required =false) String description,
                                   HttpServletRequest request)
    {

        String path = request.getSession().getServletContext().getRealPath("upload");
        return iHelpService.suggestion(token,userId,file,path,description);
    }

    /**
     *提交维修接口
     * @param token token
     * @param userId    userId
     * @param file  文件
     * @param description 故障描述
     * @param longitude 经度
     * @param latitude  纬度
     * @param addressDetail 地址详情
     * @param request   request
     * @return
     */
    @RequestMapping(value = "repair.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse repair(@RequestParam(value = "token", required = true) String token,
                                     @RequestParam(value = "userId", required = true) String userId,
                                     @RequestParam(value = "upload_file",required = false) MultipartFile file,
                                     @RequestParam(value = "description", required =false) String description,
                                     @RequestParam(value = "longitude",required = false)String longitude,
                                     @RequestParam(value = "latitude",required = false)String latitude,
                                     @RequestParam(value = "addressDetail",required = false)String addressDetail,
                                     @RequestParam(value = "deviceCheckInfo",required = false)String deviceCheckInfo,
                                     HttpServletRequest request)
    {

        String path = request.getSession().getServletContext().getRealPath("upload");
        return  iHelpService.repair(token,userId,file,path,description,longitude,latitude,addressDetail,deviceCheckInfo);
    }

    /**
     * 获取报修工单
     * @param token     token
     * @param userId    userId
     * @param pageNum   pageNum
     * @param pageSize  pageSize
     * @param orderBy   排序
     * @return          工单列表
     */
    @RequestMapping(value = "list.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse list(@RequestParam(value = "token", required = true) String token,
                               @RequestParam(value = "userId", required = true) String userId,
                               @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                               @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                               @RequestParam(value = "orderBy", defaultValue = "") java.lang.String orderBy)
    {
        return iHelpService.list(token,userId,pageNum,pageSize,orderBy);
    }
}
